class AccountController < ApplicationController

  def view
    @account = @user.accounts.find(params[:id])
    @entries = @account.entries.apply_running_total
  end

  def daily
    acct = @user.accounts.find(params[:id])
    data = acct.daily_totals

    g = Gruff::Line.new(600)
    g.title = "Daily Totals for #{acct.name}"

    labels = {}
    data.each_with_index do |h,i|
      labels[i] = h["transaction_date"]
    end

    g.hide_line_numbers = true
    g.hide_legend = true
    g.labels = labels
    g.data("balance", data.collect {|h| h["daily_total"].to_i})

    send_data(g.to_blob,
              :disposition => 'inline',
              :type => 'image/png',
              :filename => "account.png")
  end

end
